#include<iostream>
#include<queue>
using namespace std;
const int N = 2e5 + 10;
int dis[N];
bool st[N];
int ans;
int n, k;
int bfs(int x, int k)
{
	queue<int>q;
	q.push(x);
	st[x] = 1;
	while (q.size()) {
		int t = q.front();
		q.pop();
		//cout << t << " ";
		if (t == k) {
			return dis[k];
		}
		if (t - 1 >= 0 && !st[t - 1]) {
			st[t - 1] = 1;
			dis[t - 1] = dis[t] + 1;
			q.push(t - 1);
		}
		if (t - 1 < N && !st[t - 1]) {
			st[t - 1] = 1;
			dis[t - 1] = dis[t] + 1;
			q.push(t - 1);
		}
	    if (t + 1 < N && !st[t + 1]) {
			dis[t + 1] = 1;
			dis[t + 1] = dis[t] + 1;
			q.push(t + 1);
		}
		if (t * 2 < N && !st[t * 2]) {
			st[2 * t] = 1;
			dis[t * 2] = dis[t] + 1;
			q.push(t * 2);
		}
	}
}
int main()
{
	cin >> n >> k;
	if (n == k) {
		cout << 0 << endl;
		return 0;
	}
	int ret = bfs(n, k);
	cout << ret << endl;
	return 0;
}